<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>用户管理-添加</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    </head>

    <body>
    <div class="x-body">
        <form id="formAdd" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>用户账号</label>
                <div class="layui-input-inline">
                    <input type="text" id="account" name="account" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 可用于登录</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>用户姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 可用于登录</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>登录密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="password" name="password" required lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 6到16个字符</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="rePassword" required lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 6到16个字符</div>
            </div>
            <div class="layui-form-item openness">
                <label class="layui-form-label"><span class="x-red">*</span>用户性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="1" title="男性" lay-skin="primary" checked />
                    <input type="radio" name="sex" value="2" title="女性" lay-skin="primary" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red"></span>用户手机</label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">可用于登录</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" type="button" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>

    </div>
    </body>
</html>
<script src="${ctxPath}/static/manage/layui/layui.js" charset="utf-8"></script>
<script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
<script src="${ctxPath}/static/manage/js/jquery.js"></script>
<script src="${ctxPath}/static/manage/js/util.js"></script>

<script type="text/javascript">
    layui.use(['form','layer'], function(){
        var $ = layui.$, form = layui.form;

        // 监听提交
        form.on('submit(add)', function(){
            var phone = $("#phone").val();
            var password = $("#password").val();
            var rePassword = $("#rePassword").val();

            // 校验俩次密码是否一致，校验手机号是否合法
            if(password != rePassword){
                alert("俩次密码不一致，请重新输入");
                return false;
            }
            if(!checkMobile(phone)){
                alert("手机号码不合法");
                return false;
            }

            $.ajax({
                url:'/manage/user/userAdd',
                type:'post',
                data:$("#formAdd").serialize(),
                success:function(result){
                    alert(result);
                    if(result == "处理成功"){
                        window.parent.location.reload();
                    }
                },
                error:function(result){
                    alert("失败？请及时告知开发人员"+result);
                    window.parent.location.reload();
                }

            });
        });
    });
</script>

